{- |
Module      :  SudokuGrid_test.hs
Description :  Testing SudokuGrid
Copyright   :  (c) Michal Parusinski
License     :  GPLv3

Maintainer  :  mparusinski@googlemail.com
Stability   :  NOT APPLICABLE
Portability :  portable
-}

module SudokuGrid_test where 

import qualified Test.HUnit as Test
import qualified Data.Array as Array
import qualified Data.Maybe as Maybe
import qualified Data.List  as List
import Control.Monad

import SudokuGrid
import Symbols
import TestUtils
import ExampleGrids

-- TODO: TESTS

accessTest1 
    = createEqualityTest msg input (Just One)
      where msg   = "Unable to access elements properly"
            input = getElemAt exampleGrid1 (3,7)

accessTest2 
    = createEqualityTest msg input Nothing
      where msg   = "Unable to access elements properly"
            input = getElemAt exampleGrid1 (4,1)

accessTest3
    = createEqualityTest msg input expected
    where msg      = "Unable to get row"
          input    = getRowAt exampleGrid1 (3,7)
          expected = [Nothing, Nothing, Just Three, 
                      Nothing, Nothing, Nothing,
                      Just One, Just Six, Just Two]

accessTest4 
    = createEqualityTest msg input expected
    where msg      = "Unable to get rows"
          input    = getRows exampleGrid1
          expected = exampleGridList1

accessTest5
    = createEqualityTest msg input expected
    where msg      = "Unable to get col"
          input    = getColAt exampleGrid1 (2,4)
          expected = [Nothing, Just Three, Nothing,
                      Just Four, Nothing, Just Six,
                      Nothing, Just Two, Nothing]

accessTest6
    = createEqualityTest msg input expected
    where msg      = "Unable to get cols"
          input    = getCols exampleGrid1
          expected = List.transpose exampleGridList1

accessTest7
    = createEqualityTest msg input expected
    where msg      = "Unable to access elements"
          input    = dumpElements exampleGrid1
          expected = join exampleGridList1

accessTests
    = quickTestList "access tests" tests
    where tests = [accessTest1, accessTest2, accessTest3, accessTest4,
                   accessTest5, accessTest6, accessTest7]

runAccessTests
    = Test.runTestTT accessTests

runModifierTest
    = Test.runTestTT modifierTest
    where modifierTest = createEqualityTest "Modifier test" input expected
          input        = exampleGrid2
          expected     = updateGrid emptyGrid modifierList
          emptyGrid    = (createEmptyGrid 9) :: Grid DefaultSymbol

runDeleterTest
    = Test.runTestTT deleterTest
    where deleterTest = createEqualityTest "Deleter test" input expected
          input       = deleteFromGrid exampleGrid2 [(i,9) | i <- [1..9]]
          expected    = (createEmptyGrid 9) :: Grid DefaultSymbol